package com.cxs.plan.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.cxs.plan.utils.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Autowired
    HttpServletRequest request;

    @Override
    public void insertFill(MetaObject metaObject) {
        //填充创建时间
        metaObject.setValue("createTime", LocalDateTime.now());
        //填充 更新的时间
        metaObject.setValue("updateTime", LocalDateTime.now());
        Integer result = BaseContext.getCurrentId();
        //填充创建人信息
        metaObject.setValue("createUser",result);
        //填充更新人信息
        metaObject.setValue("updateUser",result);
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        //因为是更新，所以不用操作创建时间
        //更新 更新的时间
        metaObject.setValue("updateTime", LocalDateTime.now());
        Integer result = BaseContext.getCurrentId();;
        //填充更新人信息
        metaObject.setValue("updateUser",result);
    }
}